package shu;

public class _04排序数组中找和的因子 {
    /**
     * 给定已排序数组，不重复打印arr中所有相加和为k的不降序二元组？
     * 扩展题：三元组呢？
     * 如输入arr =  {-8,-4,-3,0,2,4,5,8,9,10}，k=10，那么该输出(0,10)  (2,8)
     */
    public static void main(String[] args) {
        int[] arr =  {-8,-4,-3,0,2,4,5,8,9,10};
        int k = 10;
        f(arr,k);
    }

    public static void f(int[] a,int k){
        int n = a.length;
        int begin = 0;
        int end = n -1;
        while (begin <= end){
            if (a[begin] + a[end] < k){
                begin ++;
            }else if (a[begin] + a[end] ==k){
                System.out.println("("+a[begin]+","+a[end]+")");
                begin++;
            }else {
                end --;
            }
        }
    }
}
